home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / telecomm / bbs / axshsupp.lha / AXsh-DateTime10.lha / DateTime.c < prev    next >
C/C++ Source or Header  |  1993-03-17  |  2KB  |  96 lines

  1. ;/* DateTime - a date and time shower especially for AXsh and other stdio
  2. ;              envinroments. (C) 1993 Osku Sneits / FTeam Labs. You may,
  3. ;              however, compile this for your own use on AXsh envinroment.
  4. ;              get_time() (C) by Digital Design.
  5. ;
  6. ;              you can reach me via InterNet hsneits@nyx.cs.du.edu
  7. ;
  8. ;              p.s. instructions: works just like top in AXsh :-)
  9.  
  10. lc -v -b -r DateTime.c
  11. blink root lib:c.o+DateTime.o to DateTime lib lib:lc.lib+lib:amiga.lib sc sd nd
  12. quit
  13.  
  14.     17-Mar-93    First release. Nothing better to to, so this might
  15.                         be the first and the last...
  16.  
  17. ****************************************************************************/
  18.  
  19.  
  20.  
  21. #include <exec/types.h>
  22. #include <proto/exec.h>
  23. #include <proto/dos.h>
  24. #include <stdio.h>
  25.  
  26. char *vers="$VER: version 1.0"; /* just a funny way to make CLI command
  27.                     version DateTime to show version... */
  28.  
  29. void get_time(char *);
  30.  
  31. void _main()
  32. {
  33. char dati[30];
  34.  
  35. BPTR ifp,ofp;
  36. char buf[1];
  37.  
  38. ifp = Input();
  39. ofp = Output();
  40.  
  41. for (;;)
  42.  {
  43.  get_time(dati);
  44.  Write(ofp," ",1);
  45.  Write(ofp,dati,strlen(dati));
  46.  Delay(2);
  47.  if (WaitForChar(ifp,1000000))
  48.    {
  49.    Read(ifp,buf,1);
  50.    break;
  51.    }
  52.  }
  53. }
  54.  
  55.  
  56. void get_time(char *a)            /* e.g. Sunday 16-Feb-92 18:31:47 */
  57. {    register int year=1978,day=1,month=1,i;
  58.     char wdays[7][10]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"},
  59.          months[12][4]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
  60.     unsigned int hours=0,minutes=0,seconds=0,wday=0,pos1,pos2,
  61.                  dpm[12]={31,28,31,30,31,30,31,31,30,31,30,31};
  62.     struct DateStamp v;
  63.  
  64.     DateStamp(&v);
  65.     wday=(day=v.ds_Days)%7;
  66.     while(day>=(i=365+((year%4)==0 && (year%100))))
  67.     {    day-=i;
  68.         ++year;
  69.     }
  70.     while(day>=(i=dpm[month-1]+((year%4)==0 && (year%100) && month==2)))
  71.     {    day-=i;
  72.         month++;
  73.     }
  74.     day++;
  75.     year=year%100; /* use only tens and ones */
  76.     hours=v.ds_Minute/60;
  77.     minutes=v.ds_Minute%60;
  78.     seconds=v.ds_Tick/TICKS_PER_SECOND;
  79.  
  80.     sprintf(a,"%s xx-%s-xx xx:xx:xx",wdays[wday],months[month-1]);
  81.     pos1=strlen(wdays[wday])+1;
  82.     pos2=pos1+strlen(months[month-1])+4;
  83.     a[pos1]=day/10+'0';
  84.     a[pos1+1]=day%10+'0';
  85.     a[pos2]=year/10+'0';
  86.     a[pos2+1]=year%10+'0';
  87.     a[pos2+3]=hours/10+'0';
  88.     a[pos2+4]=hours%10+'0';
  89.     a[pos2+6]=minutes/10+'0';
  90.     a[pos2+7]=minutes%10+'0';
  91.     a[pos2+9]=seconds/10+'0';
  92.     a[pos2+10]=seconds%10+'0';
  93.     a[pos2+11]=' ';
  94.     a[pos2+12]='\r';
  95. }
  96.